﻿Imports SecretaryToolData

Public Class frmIndividualReports

	Private ReadOnly Property TypedPublisherDataBindingSource As List(Of VM_PublisherInformation)
		Get
			Return CType(lstPublishers.DataSource, List(Of VM_PublisherInformation))
		End Get
	End Property

	Private Sub btnClose_Click(sender As System.Object, e As System.EventArgs) Handles btnClose.Click
		Me.Close()
	End Sub

	Private Sub frmIndividualReports_Load(sender As Object, e As System.EventArgs) Handles Me.Load
		PopulatePublishers()
	End Sub

	Public Sub New()

		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.
		PopulatePublishers()
	End Sub

	Private Sub PopulatePublishers()
		Dim publisherCollection As New List(Of VM_PublisherInformation)

		publisherCollection = PublisherData.LocalPublishers.OrderBy(Function(x) x.FullName).Select(Function(x) New VM_PublisherInformation(x.PublisherID)).ToList

		lstPublishers.DisplayMember = Extensions.GetMemberInfo(Function(x As VM_PublisherInformation) x.FullName).Name
		lstPublishers.ValueMember = Extensions.GetMemberInfo(Function(x As VM_PublisherInformation) x.PublisherID).Name
		lstPublishers.DataSource = publisherCollection

		lstPublishers.Invalidate()

	End Sub

	Private Sub txtFilter_TextChanged(sender As Object, e As System.EventArgs) Handles txtFilter.TextChanged
		lstPublishers.FilterString = txtFilter.Text
	End Sub

	Private Sub lstPublishers_KeyPress(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles lstPublishers.KeyPress
		txtFilter.Text = e.KeyChar
		txtFilter.Focus()
		txtFilter.SelectionStart = txtFilter.TextLength
	End Sub

	Private Sub btnEmergencyContactInfoReport_Click(sender As Object, e As System.EventArgs) Handles btnEmergencyContactInfoReport.Click
		Dim familyHeadList As New List(Of Long)

		For Each publisher As VM_PublisherInformation In lstPublishers.SelectedItems
			familyHeadList.Add(publisher.FamilyHeadID)
		Next

		Dim reportLocation As String = Reports.EmergencyContactInformation(familyHeadList.Distinct.ToList).FullName
		If MessageBox.Show(String.Format("Reports generated and saved at{0}{1}.{0}{0}Do you want to open it?", Environment.NewLine, reportLocation), "Report Successfully Generated", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
			Process.Start(reportlocation)
		End If

		lstPublishers.Focus()
	End Sub

	Private Sub btnTimeReport_Click(sender As Object, e As System.EventArgs) Handles btnTimeReport.Click
		Dim publishersList As New List(Of VM_PublisherInformation)

		For Each publisher As VM_PublisherInformation In lstPublishers.SelectedItems
			publishersList.Add(New VM_PublisherInformation(publisher.PublisherID))
		Next

		Dim reportLocation As String = Reports.GeneratePublishersReport(publishersList).FullName
		If MessageBox.Show(String.Format("Report generated and saved at{0}{1}.{0}{0}Do you want to open it?", Environment.NewLine, reportLocation), "Report Successfully Generated", MessageBoxButtons.YesNo, MessageBoxIcon.Information) = Windows.Forms.DialogResult.Yes Then
			Process.Start(reportLocation)
		End If

		lstPublishers.Focus()
	End Sub

End Class